<template>
  <v-chart class="chart" :option="option" autoresize />
</template>

<script>
import { defineComponent } from "vue";

import VChart from "vue-echarts";

import { use } from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";
import { GaugeChart, PieChart } from "echarts/charts";

use([CanvasRenderer, GaugeChart, PieChart]);

export default defineComponent({
  name: "RoundProgress",
  components: {
    VChart,
  },
  props: {
    title: {
      type: String,
      default: "",
    },
    color: {
      type: String,
      default: "#ffc916",
    },
  },
  data() {
    return {
      option: this.getOption(0),
    };
  },
  methods: {
    render(data) {
      this.option = this.getOption(data);
    },
    getOption(data) {
      return {
        series: [
          {
            name: "外边框",
            type: "pie",
            clockWise: false, // 顺时加载
            hoverAnimation: false, // 鼠标移入变大
            center: ["50%", "50%"],
            radius: ["80%", "80%"],
            label: false,
            animation: false,
            data: [
              {
                value: 0,
                itemStyle: {
                  normal: {
                    borderWidth: 1,
                    borderColor: "rgba(255, 255, 255, 0.6)",
                  },
                },
              },
            ],
          },
          {
            type: "gauge",
            startAngle: 90,
            endAngle: -270,
            pointer: false,
            progress: {
              show: true,
              overlap: false,
              roundCap: false,
              clip: false,
            },
            axisLine: {
              lineStyle: {
                width: 6,
                color: [[1, "rgba(255, 255, 255, 0.8)"]],
              },
            },
            splitLine: false,
            axisTick: false,
            axisLabel: false,
            data: [
              {
                value: data,
                name: this.title,
                itemStyle: {
                  color: this.color,
                },
                title: {
                  offsetCenter: ["0", "10"],
                },
                detail: {
                  valueAnimation: true,
                  offsetCenter: ["0", "-10"],
                },
              },
            ],
            title: {
              fontSize: 14,
              fontFamily: "cn",
              color: "#fff",
            },
            detail: {
              fontSize: 16,
              fontFamily: "num",
              color: "#fff",
              formatter: "{value}",
            },
          },
        ],
      };
    },
  },
});
</script>

<style lang="scss" scoped></style>
